<template>
  <div>
    <el-form ref="form" :model="form" :rules="rules" label-width="160px">
      <el-row>
        <el-col>
          <el-form-item label="被拒店员重新申请" prop="statusApplyAgain">
            <el-switch v-model="form.statusApplyAgain" :active-value="'Y'" :inactive-value="'N'"></el-switch>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col>
          <el-form-item label="动态是否需要审核" prop="statusDynamicAudit">
            <el-switch v-model="form.statusDynamicAudit" :active-value="'Y'" :inactive-value="'N'"></el-switch>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col>
          <el-form-item label="资料修改是否需要审核" prop="statusInfoAudit">
            <el-switch v-model="form.statusInfoAudit" :active-value="'Y'" :inactive-value="'N'"></el-switch>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col>
          <el-form-item label="店员是否可以取消订单" prop="statusCancelOrder">
            <el-switch v-model="form.statusCancelOrder" :active-value="'Y'" :inactive-value="'N'"></el-switch>
          </el-form-item>
        </el-col>
      </el-row>
      <!-- <el-row>
        <el-col>
          <el-form-item label="店员可以提醒顾客续单" prop="statusContinueOrder">
            <el-switch v-model="form.statusContinueOrder" :active-value="'Y'" :inactive-value="'N'"></el-switch>
          </el-form-item>
        </el-col>
      </el-row> -->
      <el-row>
        <el-col>
          <el-form-item label="是否开启等级降级" prop="statusReduceLevel">
            <div class="flex-align-center">
              <el-switch v-model="form.statusReduceLevel" :active-value="'Y'" :inactive-value="'N'"></el-switch>
              <div class="font-14 dy-font-color m-l-10 mgl10 flex">
                <el-link type="primary" :underline="false">[谨慎开启]</el-link>
                <span class="mgl5">未能保持达级需周收益则降到对应等级，在等级设置菜单中查看并设置各等级，降级后影响店员收益，默认不降级</span>
              </div>
            </div>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col>
          <el-form-item label="每周最大提现次数" prop="cashTimes">
            <div class="flex-align-center">
              <el-input-number v-model="form.cashTimes" placeholder="请输入每周最大提现次数" :min="0" :max="100" />
              <div class="font-14 dy-font-color m-l-10 mgl10 flex">
                <el-link type="primary" :underline="false">[单位：次]</el-link>
                <span class="mgl5">超出后不可提现，不填则不限制</span>
              </div>
            </div>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col>
          <el-form-item label="单笔最大提现金额" prop="amountMax">
            <div class="flex-align-center">
              <el-input-number v-model="form.amountMax" placeholder="请输入最大提现金额" :min="0" :max="100000" />
              <div class="font-14 dy-font-color m-l-10 mgl10 flex">
                <el-link type="primary" :underline="false">[单位：元]</el-link>
                <span class="mgl5">单笔可提现的最大值，0或者不填则不限制</span>
              </div>
            </div>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col>
          <el-form-item label="单笔最小提现金额" prop="amountMin">
            <div class="flex-align-center">
              <el-input-number v-model="form.amountMin" placeholder="请输入最小提现金额" :min="0" :max="100000" />
              <div class="font-14 dy-font-color m-l-10 mgl10 flex">
                <el-link type="primary" :underline="false">[单位：元]</el-link>
                <span class="mgl5">单笔可提现的最小值，0或者不填则不限制</span>
              </div>
            </div>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="reset">重 置</el-button>
    </div>
  </div>
</template>

<script>

import { getConfigEmployee, saveConfigEmployee } from "@/api/market/configEmployee";
export default {
  name: 'ConfigEmployee',
  components: {

  },
  data() {
    return {
      // 表单参数
      form: {
        shopId: "",
        statusApplyAgain: "",
        statusDynamicAudit: "",
        statusInfoAudit: "",
        statusCancelOrder: "",
        statusContinueOrder: "",
        statusReduceLevel: "N",
        cashTimes: null,
        amountMax: null,
        amountMin: null,
      },
      // 表单校验
      rules: {
      }
    }
  },
  mounted(){
    this.init()
  },
  methods: {
    init(){
      let shopId = '';
      if(process.env.NODE_ENV === 'development'){
        shopId = 'haidiyao'
      }else{
        shopId = window.location.hostname.split(".")[0];
      }
      getConfigEmployee({shopId: shopId}).then(response => {
        let p = {...this.form}
        this.form = {...p, ...response.data}
      });
    },
    // 表单重置
    reset() {
      this.form = {
        shopId: "",
        statusApplyAgain: "",
        statusDynamicAudit: "",
        statusInfoAudit: "",
        statusCancelOrder: "",
        statusContinueOrder: "",
        statusReduceLevel: "N",
        cashTimes: null,
        amountMax: null,
        amountMin: null,
      };
      this.resetForm("form");
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          let params = JSON.parse(JSON.stringify(this.form))
          if(process.env.NODE_ENV === 'development'){
            params.shopId = 'haidiyao'
          }else{
            params.shopId = window.location.hostname.split(".")[0];
          }
          saveConfigEmployee(params).then(response => {
              this.$modal.msgSuccess("保存成功");
              this.open = false;
              this.getList();
            });
        }
      });
    },
  }
}
</script>

<style lang="scss" scoped>
.width100{
  width: 100px;
}
.width300{
  width: 300px;
}
</style>
